<?php

namespace app\api\model;

use think\Model;
use traits\model\SoftDelete;

class RechargeOrder extends Model
{
    use SoftDelete;

    protected $autoWriteTimestamp = 'int';
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    protected $hidden = ['deletetime', 'updatetime', 'status'];

    public function getCreateTimeAttr($value)
    {
        return $value ? date('Y-m-d H:i:s', $value) : '';
    }

    public static function getByUserId($user_id, $length = 20)
    {
        return self::where('user_id', $user_id)->where('status', 1)->order('createtime desc')->paginate($length);
    }
}
